package com.example.xianji.activity;

import java.util.ArrayList;
import java.util.HashMap;

import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.JsonObjectRequest;
import com.example.xianji.Contant;
import com.example.xianji.XJApplication;
import com.example.xianji.R;
import com.example.xianji.adapter.Share_Adapter;
import com.example.xianji.bean.Share;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;
import com.sina.weibo.sdk.api.BaseMediaObject;
import com.sina.weibo.sdk.api.WebpageObject;
import com.sina.weibo.sdk.api.WeiboMessage;
import com.sina.weibo.sdk.api.WeiboMultiMessage;
import com.sina.weibo.sdk.api.share.BaseResponse;
import com.sina.weibo.sdk.api.share.IWeiboHandler;
import com.sina.weibo.sdk.api.share.IWeiboShareAPI;
import com.sina.weibo.sdk.api.share.SendMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.SendMultiMessageToWeiboRequest;
import com.sina.weibo.sdk.api.share.WeiboShareSDK;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.auth.WeiboAuthListener;
import com.sina.weibo.sdk.auth.sso.SsoHandler;
import com.sina.weibo.sdk.constant.WBConstants;
import com.sina.weibo.sdk.exception.WeiboException;
import com.sina.weibo.sdk.utils.Utility;
import com.tencent.connect.common.Constants;
import com.tencent.connect.share.QQShare;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.open.t.Weibo;
/*import com.tencent.mm.sdk.openapi.SendMessageToWX;
import com.tencent.mm.sdk.openapi.WXMediaMessage;
import com.tencent.mm.sdk.openapi.WXWebpageObject;*/
import com.tencent.tauth.IUiListener;
import com.tencent.tauth.Tencent;
import com.tencent.tauth.UiError;

import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class Main_ZhiWei_DetailsActivity extends Activity implements OnClickListener, IWeiboHandler.Response {
    private ImageView zhiwei_detail_back;
    //    private SharedPreferences sp;
//    private Editor ed;
    private TextView textview_job_title, zhiwei_xiangqing_xinzi, zhiwei_details_name, zhiwei_details_province,
            zhiwei_details_job_education, zhiwei_details_place, zhiwei_xiangqing_job_jinyan, zhiwei_xiangqing_type, zhiwei_details_zhize, zhiwei_details_yaoqiu, job_person_count;
    private RelativeLayout zhiwei_details_collection, relative_layout_zhiwei_share;
    private LinearLayout layout2;
    private GridView province_gridview;
    private Share_Adapter mShare_Adapter;
    private PopupWindow show_popupWindow;
    private ArrayList<Share> share_list = new ArrayList<Share>();
    private String zhiwei_detail_share;

    private SsoHandler mSsoHandler;
    private IWeiboShareAPI mWeiboShareAPI = null;
    private Oauth2AccessToken mAccessToken;

    private boolean isInstalledWeibo;
    private int supportApiLevel;
    private Weibo mWeibo;
    /**
     * 腾讯微博
     */

    IUiListener loginListener = new BaseUiListener() {
        @Override
        protected void doComplete(JSONObject values) {
            initOpenidAndToken(values);

            mWeibo = new Weibo(Main_ZhiWei_DetailsActivity.this, XJApplication.getTencent().getQQToken());
            if (ready(Main_ZhiWei_DetailsActivity.this)) {
                String content = textview_job_title.getText().toString();
                mWeibo.sendText(content, new TQQApiListener("add_t", false, Main_ZhiWei_DetailsActivity.this));
            }
        }
    };
    private Button shenqing_zhiwei;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main__zhi_wei__details);

        //XJApplication.getInstance().addActivity(this);
        zhiwei_detail_back = (ImageView) findViewById(R.id.zhiwei_detail_back);
        textview_job_title = (TextView) findViewById(R.id.textview_job_title);
        zhiwei_xiangqing_xinzi = (TextView) findViewById(R.id.zhiwei_xiangqing_xinzi);
        zhiwei_details_name = (TextView) findViewById(R.id.zhiwei_details_name);
        zhiwei_details_province = (TextView) findViewById(R.id.zhiwei_details_province);
        zhiwei_details_job_education = (TextView) findViewById(R.id.zhiwei_details_job_education);
        zhiwei_details_place = (TextView) findViewById(R.id.zhiwei_details_place);
        zhiwei_xiangqing_job_jinyan = (TextView) findViewById(R.id.zhiwei_xiangqing_job_jinyan);
        zhiwei_xiangqing_type = (TextView) findViewById(R.id.zhiwei_xiangqing_type);
        zhiwei_details_zhize = (TextView) findViewById(R.id.zhiwei_details_zhize);
        zhiwei_details_yaoqiu = (TextView) findViewById(R.id.zhiwei_details_yaoqiu);
        zhiwei_details_collection = (RelativeLayout) findViewById(R.id.zhiwei_details_collection);
        job_person_count = (TextView) findViewById(R.id.job_person_count);
        relative_layout_zhiwei_share = (RelativeLayout) findViewById(R.id.relative_layout_zhiwei_share);
        shenqing_zhiwei = (Button) findViewById(R.id.shenqing_zhiwei);

//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();

        zhiwei_detail_share = "http://zhaopin.xianjichina.com/recruit/detail_" + getIntent().getStringExtra("zhiwei_id");
        get_zhiwei_xiangqing();

        Share mShare = new Share();
        Share mShare1 = new Share();
        Share mShare2 = new Share();
        Share mShare3 = new Share();
        Share mShare4 = new Share();
        Share mShare5 = new Share();
        Share mShare6 = new Share();
        mShare.setDrawle(R.drawable.download);
        mShare.setName("微信好友");

        mShare1.setDrawle(R.drawable.friend);
        mShare1.setName("微信朋友圈");

        mShare2.setDrawle(R.drawable.weixin_collection);
        mShare2.setName("微信收藏");

        mShare3.setDrawle(R.drawable.tengxun_weibo);
        mShare3.setName("腾讯微博");

        mShare4.setDrawle(R.drawable.xinlang_weibo);
        mShare4.setName("新浪微博");

        mShare5.setDrawle(R.drawable.qie);
        mShare5.setName("QQ");

        mShare6.setDrawle(R.drawable.kongjian);
        mShare6.setName("QQ空间");
        share_list.add(mShare);
        share_list.add(mShare1);
        share_list.add(mShare2);
        share_list.add(mShare3);

        share_list.add(mShare4);
        share_list.add(mShare5);
        share_list.add(mShare6);
        zhiwei_detail_back.setOnClickListener(this);
        zhiwei_details_collection.setOnClickListener(this);

        relative_layout_zhiwei_share.setOnClickListener(this);
        shenqing_zhiwei.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.zhiwei_detail_back) {
            this.finish();
        } else if (v.getId() == R.id.zhiwei_details_collection) {
        } else if (v.getId() == R.id.relative_layout_zhiwei_share) {
            Photo_show();
            province_gridview.setAdapter(mShare_Adapter);
            show_popupWindow.showAtLocation(findViewById(R.id.zhiwei_detail), Gravity.BOTTOM, 0, 0);

            province_gridview.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1,
                                        int arg2, long arg3) {
                    if (share_list.get(arg2).getName().equals("微信好友")) {
                        weiXin_showShare();
                    } else if (share_list.get(arg2).getName().equals("微信朋友圈")) {
                        weiXin_prnyyouquan_showShare();
                    } else if (share_list.get(arg2).getName().equals("微信收藏")) {
                        weiXin_collection_showShare();
                    } else if (share_list.get(arg2).getName().equals("腾讯微博")) {
                        tengxun_weibo_share();
                    } else if (share_list.get(arg2).getName().equals("新浪微博")) {
                        WeiBo_share();
                    } else if (share_list.get(arg2).getName().equals("QQ")) {
                        QQ_Share();
                    } else if (share_list.get(arg2).getName().equals("QQ空间")) {
                        share_QQ_Qzon();
                    }
                }
            });
        } else if (v.getId() == R.id.shenqing_zhiwei) {
            Toast.makeText(this, "此功能暂时还没有开通哦!", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 微信好友
     */
    private void weiXin_showShare() {
        WXWebpageObject webpage = new WXWebpageObject();
        //webpage.webpageUrl = "http://www.baidu.com";
        webpage.webpageUrl = zhiwei_detail_share;
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = textview_job_title.getText().toString();
        msg.description = zhiwei_detail_share;
        SendMessageToWX.Req req1 = new SendMessageToWX.Req();
        req1.transaction = buildTransaction("webpage");
        req1.message = msg;
        req1.scene = SendMessageToWX.Req.WXSceneSession;
        XJApplication.getApi().sendReq(req1);
    }

    /**
     * 微信朋友圈
     */
    private void weiXin_prnyyouquan_showShare() {
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.scene = SendMessageToWX.Req.WXSceneTimeline;
        req.transaction = buildTransaction("webpage");
        req.message = new WXMediaMessage();
        req.message.title = textview_job_title.getText().toString();
        req.message.mediaObject = new WXWebpageObject(zhiwei_detail_share);
        XJApplication.getApi().sendReq(req);
    }

    /**
     * 微信收藏
     */
    private void weiXin_collection_showShare() {
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.scene = SendMessageToWX.Req.WXSceneFavorite;
        req.transaction = buildTransaction("webpage");
        req.message = new WXMediaMessage();
        req.message.title = textview_job_title.getText().toString();
        req.message.mediaObject = new WXWebpageObject(zhiwei_detail_share);
        XJApplication.getApi().sendReq(req);
    }

    /**
     * QQ
     * @return
     */
    public void QQ_Share() {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_KEY_TYPE, QQShare.SHARE_TO_QQ_TYPE_DEFAULT);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "贤集网");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, textview_job_title.getText().toString());
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, zhiwei_detail_share);
        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "贤集网");
        XJApplication.getTencent().shareToQQ(Main_ZhiWei_DetailsActivity.this, params, new IUiListener() {

            @Override
            public void onError(UiError arg0) {
            }

            @Override
            public void onComplete(Object arg0) {
            }

            @Override
            public void onCancel() {
            }
        });
    }

    public void share_QQ_Qzon() {
        final Bundle params = new Bundle();
        params.putInt(QQShare.SHARE_TO_QQ_EXT_INT, QQShare.SHARE_TO_QQ_FLAG_QZONE_AUTO_OPEN);
        params.putString(QQShare.SHARE_TO_QQ_TITLE, "贤集网");
        params.putString(QQShare.SHARE_TO_QQ_SUMMARY, textview_job_title.getText().toString());
        params.putString(QQShare.SHARE_TO_QQ_TARGET_URL, zhiwei_detail_share);

        params.putString(QQShare.SHARE_TO_QQ_APP_NAME, "贤集网");

        XJApplication.getTencent().shareToQQ(Main_ZhiWei_DetailsActivity.this, params, new IUiListener() {

            @Override
            public void onError(UiError arg0) {
            }

            @Override
            public void onComplete(Object arg0) {
            }

            @Override
            public void onCancel() {
            }
        });
    }

    private void tengxun_weibo_share() {
        XJApplication.getTencent().login(Main_ZhiWei_DetailsActivity.this, "all", loginListener);
    }

    /**
     * 腾讯微博
     */
    public void initOpenidAndToken(JSONObject jsonObject) {
        try {
            String token = jsonObject.getString(Constants.PARAM_ACCESS_TOKEN);
            String expires = jsonObject.getString(Constants.PARAM_EXPIRES_IN);
            String openId = jsonObject.getString(Constants.PARAM_OPEN_ID);
            if (!TextUtils.isEmpty(token) && !TextUtils.isEmpty(expires)
                    && !TextUtils.isEmpty(openId)) {
                XJApplication.getTencent().setAccessToken(token, expires);
                XJApplication.getTencent().setOpenId(openId);
            }
        } catch (Exception e) {
        }
    }

    /**
     * 腾讯微博是否登录
     *
     * @param context
     * @return
     */
    public boolean ready(Context context) {
        if (XJApplication.getTencent() == null) {
            return false;
        }
        boolean ready = XJApplication.getTencent().isSessionValid()
                && XJApplication.getTencent().getQQToken().getOpenId() != null;
        if (!ready) {
            Toast.makeText(context, "login and get openId first, please!",
                    Toast.LENGTH_SHORT).show();
        }
        return ready;
    }

    /**
     * 新浪微博
     */
    private void WeiBo_share() {
        mSsoHandler = new SsoHandler(Main_ZhiWei_DetailsActivity.this, XJApplication.mAuthInfo);
        mSsoHandler.authorizeClientSso(new AuthListener());
        mWeiboShareAPI = WeiboShareSDK.createWeiboAPI(Main_ZhiWei_DetailsActivity.this, "4216978203");
        mWeiboShareAPI.registerApp();
        isInstalledWeibo = mWeiboShareAPI.isWeiboAppInstalled();
        supportApiLevel = mWeiboShareAPI.getWeiboAppSupportAPI();
        mWeiboShareAPI.handleWeiboResponse(getIntent(), Main_ZhiWei_DetailsActivity.this);
    }

    @Override
    public void onResponse(BaseResponse baseResp) {
        if (baseResp != null) {
            switch (baseResp.errCode) {
                case WBConstants.ErrorCode.ERR_OK:
                    Toast.makeText(this, "成功", Toast.LENGTH_LONG).show();
                    break;
                case WBConstants.ErrorCode.ERR_CANCEL:
                    Toast.makeText(this, "取消", Toast.LENGTH_LONG).show();
                    break;
                case WBConstants.ErrorCode.ERR_FAIL:
                    Toast.makeText(this, "Error Message: " + baseResp.errMsg,
                            Toast.LENGTH_LONG).show();
                    break;
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // SSO 授权回调
        // 重要：发起 SSO 登陆的 Activity 必须重写 onActivityResults
        if (mSsoHandler != null) {
            mSsoHandler.authorizeCallBack(requestCode, resultCode, data);
        }

        if (requestCode == Constants.REQUEST_LOGIN ||
                requestCode == Constants.REQUEST_APPBAR) {
            Tencent.onActivityResultData(requestCode, resultCode, data, loginListener);
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    private BaseMediaObject getWebpageObj() {
        WebpageObject mediaObject = new WebpageObject();
        mediaObject.identify = Utility.generateGUID();
        mediaObject.title = textview_job_title.getText().toString();
        mediaObject.description = "贤集网" + zhiwei_detail_share;

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.touxiang);
        mediaObject.setThumbImage(bitmap);
        mediaObject.actionUrl = zhiwei_detail_share;
        mediaObject.defaultText = "";
        return mediaObject;
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        mWeiboShareAPI.handleWeiboResponse(intent, this);
    }

    private String buildTransaction(final String type) {
        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
    }

    /**
     * 获取详情
     */
    public void get_zhiwei_xiangqing() {
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("token", PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TOKEN, ""));
        map.put("rid", getIntent().getStringExtra("zhiwei_id"));
        JSONObject params = new JSONObject(map);

        JsonObjectRequest request = new JsonObjectRequest(Method.POST, Contant.zhiwei_xiangqing,
                params, new Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject response) {
                try {
                    if (response.getInt("status") == 1) {
                        JSONObject object = response.getJSONObject("data");
                        textview_job_title.setText(object.getString("job_title"));
                        if (object.getInt("job_salary") == 1) {
                            zhiwei_xiangqing_xinzi.setText("1000-2000 元/月");
                        } else if (object.getInt("job_salary") == 2) {
                            zhiwei_xiangqing_xinzi.setText("2001-4000 元/月");
                        } else if (object.getInt("job_salary") == 3) {
                            zhiwei_xiangqing_xinzi.setText("4001-6000 元/月");
                        } else if (object.getInt("job_salary") == 4) {
                            zhiwei_xiangqing_xinzi.setText("6001-8000 元/月");
                        } else if (object.getInt("job_salary") == 5) {
                            zhiwei_xiangqing_xinzi.setText("8001-10000 元/月");
                        } else if (object.getInt("job_salary") == 6) {
                            zhiwei_xiangqing_xinzi.setText("10001-15000 元/月");
                        } else if (object.getInt("job_salary") == 7) {
                            zhiwei_xiangqing_xinzi.setText("15000-25000 元/月");
                        } else if (object.getInt("job_salary") == 8) {
                            zhiwei_xiangqing_xinzi.setText("25000 以上");
                        } else if (object.getInt("job_salary") == 9) {
                            zhiwei_xiangqing_xinzi.setText("面议");
                        }
                        zhiwei_details_name.setText(object.getString("com_name"));
                        zhiwei_details_province.setText(object.getJSONObject("jprovince").getString("name"));
                        if (object.getInt("job_education") == 1) {
                            zhiwei_details_job_education.setText("初中");
                        } else if (object.getInt("job_education") == 2) {
                            zhiwei_details_job_education.setText("中技");
                        } else if (object.getInt("job_education") == 3) {
                            zhiwei_details_job_education.setText("高中");
                        } else if (object.getInt("job_education") == 4) {
                            zhiwei_details_job_education.setText("中专");
                        } else if (object.getInt("job_education") == 5) {
                            zhiwei_details_job_education.setText("大专");
                        } else if (object.getInt("job_education") == 6) {
                            zhiwei_details_job_education.setText("本科");
                        } else if (object.getInt("job_education") == 7) {
                            zhiwei_details_job_education.setText("硕士");
                        } else if (object.getInt("job_education") == 8) {
                            zhiwei_details_job_education.setText("MBA");
                        } else if (object.getInt("job_education") == 9) {
                            zhiwei_details_job_education.setText("EMBA");
                        } else if (object.getInt("job_education") == 10) {
                            zhiwei_details_job_education.setText("博士");
                        } else if (object.getInt("job_education") == 11) {
                            zhiwei_details_job_education.setText("其他");
                        }
                        zhiwei_details_place.setText(object.getJSONObject("jprovince").getString("name") + "  " + object.getJSONObject("jcity").getString("name"));
                        if (object.getInt("job_exp") == 0) {
                            zhiwei_xiangqing_job_jinyan.setText("不限");
                        } else if (object.getInt("job_exp") == 1) {
                            zhiwei_xiangqing_job_jinyan.setText("1-3 年");
                        } else if (object.getInt("job_exp") == 2) {
                            zhiwei_xiangqing_job_jinyan.setText("3-5 年");
                        } else if (object.getInt("job_exp") == 3) {
                            zhiwei_xiangqing_job_jinyan.setText("5-10 年");
                        } else if (object.getInt("job_exp") == 4) {
                            zhiwei_xiangqing_job_jinyan.setText("10年以上");
                        }
                        if (object.getInt("job_property") == 1) {
                            zhiwei_xiangqing_type.setText("全职");
                        } else if (object.getInt("job_property") == 2) {
                            zhiwei_xiangqing_type.setText("兼职");
                        } else if (object.getInt("job_property") == 3) {
                            zhiwei_xiangqing_type.setText("实习");
                        }
                        zhiwei_details_zhize.setText(object.getString("job_duty"));
                        zhiwei_details_yaoqiu.setText(object.getString("job_qualify"));
                        job_person_count.setText(object.getString("job_person_count"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        XJApplication.getHttpQueues().cancelAll("abcPost");
        request.setTag("abcPost");
        request.setRetryPolicy(new DefaultRetryPolicy(50 * 1000, 1, 1.0f));
        XJApplication.getHttpQueues().add(request);
        XJApplication.getHttpQueues().start();
    }

    private void Photo_show() {
        layout2 = (LinearLayout) LayoutInflater.from(
                Main_ZhiWei_DetailsActivity.this).inflate(
                R.layout.province_popoupwindow_listview, null);
        province_gridview = (GridView) layout2.findViewById(R.id.province_gridview);
        mShare_Adapter = new Share_Adapter(this, share_list);
        //province_gridview.setCacheColorHint(0);
        province_gridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
        show_popupWindow = new PopupWindow(layout2, WindowManager.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setBackgroundDrawable(new BitmapDrawable());


        show_popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        show_popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        show_popupWindow.update();
        show_popupWindow.setOutsideTouchable(true);
        show_popupWindow.setFocusable(true);
        show_popupWindow.setContentView(layout2);
    }

    /**
     * 腾讯微博
     */
    private class BaseUiListener implements IUiListener {

        @Override
        public void onComplete(Object response) {
            if (null == response) {
                Toast.makeText(Main_ZhiWei_DetailsActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                return;
            }
            JSONObject jsonResponse = (JSONObject) response;
            if (null != jsonResponse && jsonResponse.length() == 0) {
                Toast.makeText(Main_ZhiWei_DetailsActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
                return;
            }
            doComplete((JSONObject) response);
        }

        protected void doComplete(JSONObject values) {
        }

        @Override
        public void onError(UiError e) {
            Toast.makeText(Main_ZhiWei_DetailsActivity.this, e.errorDetail, Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onCancel() {
            Toast.makeText(Main_ZhiWei_DetailsActivity.this, "oncancle", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 腾讯微博
     *
     * @author me
     */
    private class TQQApiListener extends BaseUiListener {
        private String mScope = "all";
        private Boolean mNeedReAuth = false;
        private Activity mActivity;

        public TQQApiListener(String mScope, Boolean mNeedReAuth, Activity mActivity) {
            super();
            this.mScope = mScope;
            this.mNeedReAuth = mNeedReAuth;
            this.mActivity = mActivity;
        }

        @Override
        public void onComplete(Object response) {
            final Activity activity = Main_ZhiWei_DetailsActivity.this;
            try {
                JSONObject json = (JSONObject) response;
                int ret = json.getInt("ret");

                if (ret == 0) {
                    Toast.makeText(Main_ZhiWei_DetailsActivity.this, "微博发送成功", Toast.LENGTH_SHORT).show();
                } else if (ret == 100030) {
                    if (mNeedReAuth) {
                        Runnable r = new Runnable() {
                            public void run() {
                                XJApplication.getTencent().reAuth(activity,
                                        mScope, new BaseUiListener());
                            }
                        };
                        Main_ZhiWei_DetailsActivity.this.runOnUiThread(r);
                    }
                } else if (ret == 6) {
                    Toast.makeText(Main_ZhiWei_DetailsActivity.this, "该账号未开通微博", Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    class AuthListener implements WeiboAuthListener {

        @Override
        public void onComplete(Bundle values) {
            mAccessToken = Oauth2AccessToken.parseAccessToken(values);
            String phoneNum = mAccessToken.getPhoneNum();
            if (mAccessToken.isSessionValid()) {
                if (isInstalledWeibo) {
                    if (mWeiboShareAPI.isWeiboAppSupportAPI()) {
                        if (supportApiLevel >= 10351 /* ApiUtils.BUILD_INT_VER_2_2 */) {

                            WeiboMultiMessage weiboMessage = new WeiboMultiMessage();

                            weiboMessage.mediaObject = getWebpageObj();

                            SendMultiMessageToWeiboRequest request = new SendMultiMessageToWeiboRequest();
                            request.transaction = String.valueOf(System.currentTimeMillis());
                            request.multiMessage = weiboMessage;
                            mWeiboShareAPI.sendRequest(Main_ZhiWei_DetailsActivity.this, request);
                        } else {
                            WeiboMessage weiboMessage = new WeiboMessage();
                            weiboMessage.mediaObject = getWebpageObj();
                            SendMessageToWeiboRequest request = new SendMessageToWeiboRequest();
                            request.transaction = String.valueOf(System.currentTimeMillis());
                            request.message = weiboMessage;
                            mWeiboShareAPI.sendRequest(Main_ZhiWei_DetailsActivity.this, request);
                        }
                    }
                }
                Toast.makeText(Main_ZhiWei_DetailsActivity.this,
                        "授权成功", Toast.LENGTH_SHORT).show();
            } else {
                String code = values.getString("code");
                Toast.makeText(Main_ZhiWei_DetailsActivity.this, "授权失败", Toast.LENGTH_LONG).show();
            }
        }


        @Override
        public void onCancel() {
            Toast.makeText(Main_ZhiWei_DetailsActivity.this,
                    "取消", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onWeiboException(WeiboException e) {
            Toast.makeText(Main_ZhiWei_DetailsActivity.this,
                    "Auth exception : " + e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }
}
